<!DOCTYPE html>
<html>
<head>
    <title>{$wishConfig.shareTitle}</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="email=no" />
    <link rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" onerror="_cdnFallback(this)">
    <link type="text/css" rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/zepto.alert.css" />
    <link type="text/css" rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/wish/index.css" />
    <script type='text/javascript' src='{$Think.config.RESOURCEURL}wx_assets/js/json2.js'></script>
    <script type='text/javascript' src='{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js'></script>

    <script src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.alert.js" type="text/javascript"></script>

     <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}"></script>  

</head>
<body>
      <div class="page">
        <div class="top-pic">
            <img src="{$wishConfig.bannelUrl}" />
            <div class="user-head">
                <img src="{$userInfo.headimgurl}" />
            </div>
            <div class="user-nick">
                {$userInfo.nickname}
            </div>
            <if condition="$wishInfo.wishText neq ''">
                <div class="user-wish" id="UserWish">
                    {$wishInfo.wishText}
                </div>
            </if>
        </div>
        <if condition="$isMe eq '1'">
            <ul class="wish-tab" id="WishTab">
                <li class="act">
                    心愿单</li>
                <li>
                    已实现 (&nbsp;{$proListcomCount}&nbsp;)</li>
            </ul>
        </if>
        <if condition="$isMe eq 1">
        <div class="tab-con" id="TabCon">
            <div class="tab-item" style="display: block;">
                <if condition="count($proList) gt 0 ">
                <div class="wish-pros" id="WishPros">
                    <foreach name="proList" item="vo">
                        <dl data-id="{$vo.id}">
                            <dt>
                                <a href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=product&method=getProduct&params=%7B"id"%3A"{$vo.id}"%7D'><img src="{$vo.picUrl}" /></a></dt>
                            <dd>
                                <div class="pro-pros">
                                    <div class="pro-name">
                                        <a href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=product&method=getProduct&params=%7B"id"%3A"{$vo.id}"%7D'>{$vo.name}</a>
                                    </div>
                                    <div class="pro-price">
                                        市场价：<s>￥{$vo.fixedPrice}</s>
                                        <if condition="$vo.discountedPrice neq ''">
                                        <br />
                                        促销价：<span>￥{$vo.discountedPrice}</span>
                                        </if>
                                        <input  type="hidden" id="hide_price_{$vo.id}" value="{$vo.fixedPrice}">
                                        <input  type="hidden" id="hide_discountedPrice_{$vo.id}" value="{$vo.discountedPrice}">
                                        <input  type="hidden" id="hide_num_{$vo.id}" value="{$vo.inventoryCount}">
                                        <if condition="$vo.buyUserName neq ''">
                                            <div class="wish-complete"></div>
                                        <else/>
                                            <if condition="$vo.inventory eq '1' and $vo.inventoryCount lt 1">
                                                <br />
                                                <span>已售罄</span>
                                            </if>
                                        </if>
                                    </div>
                                </div>
                                <if condition="$vo.buyUserName eq ''">
                                    <a <if condition="$vo.buyUserName eq ''"></if> data-id="{$vo.id}" id="BtnGive{$vo.id}"  class='btn-give <if condition="$vo.inventory and $vo.inventoryCount lt 1">btn-disabled</if> <if condition="$vo.buyUserName neq ''">btn-disabled</if>'>我要送TA</a>
                                    <else/>
                                    <a data-id="{$vo.id}" id="BtnGive{$vo.id}" style="visibility: hidden">我要送TA</a>
                                </if>
                            </dd>
                        </dl>
                    </foreach>
                </div>
                <else />
                  <div class="wish-no">您还没有心愿，去创建一个吧</div>
                </if>
            </div>
            <div class="tab-item" style="margin-top:10px">
                <ul class="co-list">
                    <foreach name="proListcom" item="user">
                    <li>
                        <dl class="user-info">
                            <dt>
                                <img src="{$user.headimgurl}" />
                            </dt>
                            <dd>
                                <div class="fl">{$user.nickname}</div>
                                <div class="fr">{$user.buyTime}</div>
                            </dd>
                        </dl>
                        <div class="liuyan">
                            {$user.buyWishText}
                        </div>
                        <div class="shixian-pro">
                            <foreach name="user.proList" item="vo">
                                <dl>
                                    <dt>
                                        <a href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&userName={$userName}&module=product&method=getProduct&params=%7B"id"%3A"{$vo.id}"%7D'><img src="{$vo.picUrl}" /></a>
                                    </dt>
                                    <dd>
                                        <div class="pro-name">
                                            <a href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&userName={$userName}&module=product&method=getProduct&params=%7B"id"%3A"{$vo.id}"%7D'>{$vo.name}</a>
                                        </div>
                                        <div class="pro-price">
                                            <s>￥{$vo.fixedPrice}</s>
                                            <if condition="$vo.discountedPrice neq ''">
                                            <br />
                                            <span>￥{$vo.discountedPrice}</span>
                                            </if>
                                            <br />
                                            × 1
                                        </div>
                                    </dd>
                                </dl>
                            </foreach>
                        </div>
                    </li>
                    </foreach>
                </ul>
            </div>
        </div>
    </div>
    <else /> 
        <if condition="count($proList) gt 0 ">
            <div class="wish-pros" id="WishPros">
                <foreach name="proList" item="vo">
                    <dl data-id="{$vo.id}">
                        <dt>
                            <a href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&userName={$userName}&module=product&method=getProduct&params=%7B"id"%3A"{$vo.id}"%7D'><img src="{$vo.picUrl}" /></a></dt>
                        <dd>
                            <div class="pro-pros">
                                <div class="pro-name">
                                    <a href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&userName={$userName}&module=product&method=getProduct&params=%7B"id"%3A"{$vo.id}"%7D'>{$vo.name}</a>
                                </div>
                                <div class="pro-price">
                                    市场价：<s>￥{$vo.fixedPrice}</s>
                                    <if condition="$vo.discountedPrice neq ''">
                                        <br />
                                        促销价：<span>￥{$vo.discountedPrice}</span>
                                    </if>
                                    <input  type="hidden" id="hide_price_{$vo.id}" value="{$vo.fixedPrice}">
                                    <input  type="hidden" id="hide_discountedPrice_{$vo.id}" value="{$vo.discountedPrice}">
                                    <input  type="hidden" id="hide_num_{$vo.id}" value="{$vo.inventoryCount}">
                                    <if condition="$vo.buyUserName neq ''">
                                        <div class="wish-complete"></div>
                                    <else/>
                                        <if condition="$vo.inventory eq '1' and $vo.inventoryCount lt 1">
                                            <br />
                                            <span>已售罄</span>
                                        </if>
                                    </if>
                                </div>
                            </div>
                            <if condition="$vo.buyUserName eq ''">
                                <a data-id="{$vo.id}" id="BtnGive{$vo.id}" class='btn-give <if condition="$vo.inventory eq '1' and $vo.inventoryCount lt 1">btn-disabled</if>'>我要送TA</a>
                            <else/>
                                <a data-id="{$vo.id}" id="BtnGive{$vo.id}" style="visibility: hidden">我要送TA</a>
                            </if>
                        </dd>
                    </dl>
                </foreach>
            </div>
            <else />
              <div class="wish-no">TA目前还没有心愿</div>
            </if>
        </div>
    </if>
    <div class="page-fixed" id="CreateBox">
        <a class="create-btn" href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=wish&method=createWish&params=%7B"actId"%3A"{$actId}"%7D'>创建我的心愿单</a>
    </div>
    <div class="page-fixed buycar-box" id="BuyBox" style="display:none">
        <div class="car-left">
            共计：<em id="number">1</em>件<br />
            <span id="Amount">￥96.00</span>
        </div>
        <a class="btn-go" id="BtnGo">去付款</a>
    </div>
    <div class='mask' id='Mask1'>
        <a class="close">&nbsp;</a>
        <div class="share1"></div>
    </div>
    <div class='mask' id='Mask2'>
        <div class="share2"></div>
        <a class="btn-know">我知道了</a>
    </div>

    <script type="text/javascript">
        var baseUrl = '{$Think.config.SERVER_HOST}';
        var touchClose=0;
        var wish = {
            init: function() {
                this._initWishBox();
                this._createMask();
                this._initBtnEvent();
                this._initTab();
                this._getCart();
            },
            _createMask: function() {
                var maxWidth = $(window).width(),
                    maxHeight = $(window).height();
                var shareId=$.util.getParam('shareId');
                var me=this;
                if(shareId){
                    if(!$.util.cookie("xinyuandanindexother")) {
                        $("#Mask2").css({
                            width: maxWidth + 'px',
                            height: maxHeight + 'px'
                        })
                        .show();
                        $.util.cookie("xinyuandanindexother",1,{path:"/",expires:365});
                        document.addEventListener('touchmove', function(event) {
                            if(!touchClose) {
                                if(event.target.type == 'range') return;
                                event.preventDefault();
                            }
                        },false);
                    }
                } else{
                    if($.util.getParam("show")) {
                        $("#Mask1").css({
                            width: maxWidth + 'px',
                            height: maxHeight + 'px'
                        })
                        .show();
                        document.addEventListener('touchmove', function(event) {
                            if(!touchClose) {
                                if(event.target.type == 'range') return;
                                event.preventDefault();
                            }
                        },false);
                    }
                }
            },
            _initTab: function() {
                var tabs = $("#WishTab > li");
                tabs.click(function() {
                    $(this).addClass('act').siblings().removeClass("act");
                    var index = tabs.index($(this));
                    $("#TabCon .tab-item").hide().eq(index).show();
                });
            },
            updateAmount:function(){
                var sumNum=0;
                var sumAmount=0;
                $("#WishPros > dl").each(function(){
                    var id=$(this).attr("data-id");
                    var num=parseInt($("#hide_num_"+id).val());
                    var price=$("#hide_price_"+id).val();
                    var discountedPrice=$("#hide_discountedPrice_"+id).val();
                    if(!num || num==="0") {
                        num=1;
                    }
                    if(discountedPrice){
                        price=discountedPrice;
                    }
                    var isGive=$(this).find('.btn-give');
                    if(num > 0 && isGive.hasClass("btn-act")){
                        sumNum++;
                        sumAmount+=parseFloat(price);
                    }
                });
                $("#number").html(sumNum);
                $("#Amount").html("￥"+parseFloat(sumAmount).toFixed(2));
            },
            _getCart:function(){
               var me = this;
               var customerId = $.util.getParam("customerId");
               var userName = $.util.getParam("userName");
               var postUrl = baseUrl + 'call.json?customerId={$customerId}';
               var data={
                      type:"buy",
                      sid:-1
                };
               var params = {
                    'module': 'product',
                    'method' :'getCart',
                    'userName':"{$userName}",
                    'params' : JSON.stringify(data)
                };
                $.ajax({
                    url: postUrl,
                    dataType: "json",
                    type: "get",
                    data: params,
                    success:function (data) {
                        if(data && data.productList){
                            var list=data.productList;
                            $.each(list,function(i,n){
                                me._addRemoveToCart(n.id,0);
                            }); 
                        }
                    }
                });
            },
            /*添加删除商品购物车*/
            _addRemoveToCart:function(pid,type){
               var me = this;
               var customerId = $.util.getParam("customerId");
               var userName = $.util.getParam("userName");
               var postUrl = baseUrl + 'call.json?customerId={$customerId}';
               var data={
                      pid:pid,
                      count:1,
                      type:"buy",
                      sid:-1
                };
               var params = {
                    'module': 'product',
                    'method' :type ? 'updateOrderDetail' : 'removeOrderDetail',
                    'params' : JSON.stringify(data),
                    'userName':"{$userName}"
                };
                $.ajax({
                    url: postUrl,
                    dataType: "json",
                    type: "POST",
                    data: params,
                    success:function (data) {
                        if(data.errCode) {
                            $.util.alert(data.msgType ? data.errMsg : "操作购物车失败，请稍候再试")
                        }
                    }
                });
            },
            prevSubmitOrder:function(){
                var pids=[];
                var customerId = $.util.getParam("customerId");
                var userName = $.util.getParam("userName");
                var buyNum=[];
                $("#WishPros > dl").each(function(){
                    var id=$(this).attr("data-id");
                    var num=$("#hide_num_"+id).val();
                    var isGive=$(this).find('.btn-give');
                    if(!num || num==="0") {
                        num=1;
                    }
                    if(num > 0 && isGive.hasClass("btn-act")){
                        pids.push(id);
                        buyNum.push(1);
                    }
                });
                var postUrl = baseUrl + 'call.json?customerId={$customerId}';
                var data={
                    pids:pids.join(","),
                    counts:buyNum.join(","),
                    type:"buy",
                    sid:-1,
                    'module':"wish",
                    'method':"updateOrderInfo",
                    'moduleId':'{$wishInfo.id}'
                };
                var params = {
                    'module': 'product',
                    'method' : 'preSubmitOrder',
                    'params' : JSON.stringify(data),
                    'userName':"{$userName}"
                };
                $.ajax({
                    url: postUrl,
                    dataType: "json",
                    type: "POST",
                    data: params,
                    success:function(data){
                        if (data.hasOwnProperty('code')) {
                            $.util.alert(data.msg);
                            $("#BtnGo").removeClass("btn_disabled");
                        } else {
                            var shareId='{$userName}';
                            var wishId='{$wishInfo.id}';
                            location.href = baseUrl + 'call.html?customerId={$customerId}&module=wish&method=getOrderDetail&params={"id":"' + data.id+'","shareId":"'+shareId+'","wishId":"'+wishId+'"}';
                        }
                    }
                });
            },
            _initBtnEvent: function() {
                var me=this;
                $("#WishPros a.btn-give").click(function() {
                   var id=$(this).attr("data-id");
                   if(!$(this).hasClass("btn-disabled")) {
                        if ($(this).hasClass("btn-act")) {
                            $(this).removeClass("btn-act");
                            if($("#WishPros a.btn-act").size() < 1) {
                                $("#BuyBox").hide();
                                $("#CreateBox").show();
                            }
                            me._addRemoveToCart(id,0);
                        } else {
                            $(this).addClass("btn-act");
                            $("#BuyBox").show();
                            $("#CreateBox").hide();
                            me._addRemoveToCart(id,1);
                        }
                       me.updateAmount();
                   }
                });
                if($("#WishPros a.btn-give").size()<1) {
                    $("#BuyBox").hide();
                    $("#CreateBox").show();
                }
                $("#Mask1 .close").click(function(){
                    $("#Mask1").hide();
                    touchClose=1;
                });
                $("#Mask2 .btn-know").click(function(){
                    $("#Mask2").hide();
                    touchClose=1;
                });
                $("#BtnGo").click(function(){
                    if(!$(this).hasClass("btn_disabled")) {
                       $(this).addClass("btn_disabled");
                       me.prevSubmitOrder();
                    }
                });
            },
            _initWishBox: function() {
                var maxWidth = $(window).width();
                $("#UserWish").css("width", Math.ceil(maxWidth / 2) - 60 + 'px');
            }
        }
        wish.init();
        var shareUrl=baseUrl+'call.html?customerId={$customerId}&module=wish&method=index&params=%7B%22actId%22%3A%22{$actId}%22%2C%22shareId%22%3A%22{$userName}%22%7D';
        var wishText='';
        wx_share.init({
            "title":"{$wishConfig.shareTitle}",
            "desc":'{$wishInfo.wishText}',
            "link":shareUrl,
            "imgUrl":"{$wishConfig.sharePicUrl}",
            "pkg":{
                "appId": '{$pkg.appId}',
                "timestamp": {$pkg.timestamp},
                "nonceStr": '{$pkg.nonceStr}',
                "signature": '{$pkg.signature}'
            },
            success:function(config,shareType){
                
            }
         });
    </script>

</body>
</html>
